bosfore_app.controller("ctrlRead",['$scope','$http',function($scope,$http){
	$scope.currentPage = 1;
	$scope.pageSize = 4;
	$scope.totalCount = 0;
	$scope.totalPages = 0;
	
	$scope.prev = function() {
		if($scope.currentPage>1) {
			$scope.selectPage($scope.currentPage-1);
		}
	}
	
	$scope.next = function() {
		if($scope.currentPage<totalPages) {
			$scope.selectPage($scope.currentPage+1);
		}
	}
	
	$scope.selectPage = function(page) {
		if($scope.totalPages!=0&(page<1||page>$scope.totalPages)) {
			return;
		}
		
		$http({
			method:'GET',
			url:'promotion_pageQuery.action',
			params:{
				"page":page,
				"rows":$scope.pageSize
			}
		}).success(function(data,status,headers,config){
			//显示表格数据
			$scope.pageItems = data.pageData;
			$scope.totalCount = data.totalCount;
			$scope.totalPages = Math.ceil($scope.totalCount/$scope.pageSize);
			
			$scope.currentPage = page;
			
			var begin;
			var end;
			
			begin = page-5;
			//page=7,begin=2,total=8
			if(begin<0) {
				begin = 1;
			}
			//end=11
			end = begin+9;
			if(end>$scope.totalPages){
				end=$scope.totalPages;
			}
			//end=8
			//begin=2 2-8不足10
			begin = end -9;
			//begin=1
			if(begin<1) {
				begin = 1;
			}
			//begin=1
			$scope.pageList = new Array();
			for(var i=begin;i<end;i++) {
				$scope.pageList.push(i);
			}
			
		}).error(function(data,status,headers,config){
			alert("出错，请联系管理员");
		}) ;
	}
	
	$scope.isActivePage=function(page) {
		return page == $scope.currentPage;
	}
	//发起请求，显示第一页数据
	$scope.selectPage($scope.currentPage);
}])